home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / Terminal 2.2 / Project / Sources / PortOptions.c < prev    next >
Text File  |  1992-01-17  |  4KB  |  162 lines

  1. /*
  2.     Terminal 2.2
  3.     "PortOptions.c"
  4. */
  5.  
  6. #ifdef THINK_C
  7. #include "MacHeaders"
  8. #endif
  9. #ifdef applec
  10. #pragma load ":(Objects):MacHeadersMPW"
  11. #pragma segment Options
  12. #endif
  13.  
  14. #include "Options.h"
  15. #include "Strings.h"
  16. #include "Utilities.h"
  17. #include "Text.h"
  18. #include "Main.h"
  19. #include "Port.h"
  20. #include "Procedure.h"
  21. #include "Popup.h"
  22.  
  23. #define B_OK        1    /* OK button */
  24. #define B_CANCEL    2    /* Cancel button */
  25.  
  26. #define U_POPUP1    3    /* Id of first popup menu user item */
  27. #define U_PORT        3    /* Port name */
  28. #define U_BAUD        4    /* Baud rate */
  29. #define U_DATA        5    /* Data bits */
  30. #define U_PARITY    6    /* Parity */
  31. #define U_STOP        7    /* Stop bits */
  32. #define U_HANDSHAKE    8    /* Handshake mode */
  33. #define U_POPUP2    8    /* Id of last popup menu user item */
  34.  
  35. #define C_DROP_DTR    9    /* Don't drop DTR when quitting */
  36. #define U_TITLELINE    10    /* Underline */
  37.  
  38. #define M_PORT        200    /* Menu, port */
  39. #define M_BAUD        201    /* Menu, baud */
  40. #define M_DATA        202    /* Menu, data bits */
  41. #define M_PARITY    203    /* Menu, parity */
  42. #define M_STOP        204    /* Menu, stop bits */
  43. #define M_HANDSHAKE    205    /* Menu, handshake */
  44.  
  45. static POPUP Popup[] = {    /* Popup menu info */
  46.     { U_PORT, M_PORT, 0, 0 },
  47.     { U_BAUD, M_BAUD, 0, 0 },
  48.     { U_DATA, M_DATA, 0, 0 },
  49.     { U_PARITY, M_PARITY, 0, 0 },
  50.     { U_STOP, M_STOP, 0, 0 },
  51.     { U_HANDSHAKE, M_HANDSHAKE, 0, 0 },
  52.     { 0, 0, 0, 0 }
  53. };
  54.  
  55. #define I_PORT        0
  56. #define I_BAUD        1
  57. #define I_DATA        2
  58. #define I_PARITY    3
  59. #define I_STOP        4
  60. #define I_HANDSHAKE    5
  61.  
  62. /* ----- Filter function for dialog ------------------------------------ */
  63.  
  64. static pascal Boolean Filter(
  65.     register DialogPtr dialog,
  66.     register EventRecord *event,
  67.     register short *item)
  68. {
  69.     SetPort(dialog);
  70.     *item = 0;
  71.     switch (event->what) {
  72.         case keyDown:
  73.             return DialogKeydown(dialog, event, item);
  74.         case mouseDown:
  75.             return PopupMousedown(dialog, event, item);
  76.     }
  77.     return FALSE;
  78. }
  79.  
  80. /* ----- Loop thru registered serial ports ----------------------------- */
  81.  
  82. static short CurrentMenuItem;
  83.  
  84. static short LoopSerial(short index, Byte *name, Byte *input, Byte *output)
  85. {
  86. #pragma unused(input, output)
  87.     register POPUP *p = &Popup[I_PORT];
  88.  
  89.     /* This AppendMenu() followed by SetItem() is necessary if there are
  90.     any of the menu meta characters ( ';' '^' '!' '<' '/' '(' ) in the
  91.     character string. These characters may be a valid part of the port
  92.     name. */
  93.  
  94.     if (!p->h)
  95.         return TRUE;    /* Stop */
  96.     AppendMenu(p->h, "\p ");
  97.     SetItem(p->h, ++CurrentMenuItem, name);
  98.     if (EqualString(name, Settings.portName, FALSE, TRUE))
  99.         p->choice = index + 1;
  100.     return FALSE;        /* Continue */
  101. }
  102.  
  103. /* ----- Port options dialog ------------------------------------------- */
  104.  
  105. void PortOptions(void)
  106. {
  107.     register DialogPtr dialog;
  108.     short number, err;
  109.     short baud, data, parity, stop;
  110.     Byte port[256];
  111.  
  112.     CenterDialog('DLOG', DLOG_PORT);
  113.     if (!(dialog = GetNewDialog(DLOG_PORT, 0, (WindowPtr)-1L)))
  114.         return;
  115.  
  116.     /* Build port menu and setup popup menus */
  117.     if (Popup[I_PORT].h = GetMenu(M_PORT)) {
  118.         Popup[I_PORT].choice = CurrentMenuItem = 1;
  119.         SerialDevice((ProcPtr)LoopSerial);
  120.     }
  121.     PopupInit(dialog, Popup);
  122.  
  123.     SetUserItem(dialog, U_TITLELINE, (ProcPtr)DrawUserLine);
  124.     SerialGetSetup(Settings.portSetup, &baud, &data, &parity, &stop);
  125.     Popup[I_BAUD].choice = baud + 1;
  126.     Popup[I_DATA].choice = data + 1;
  127.     Popup[I_PARITY].choice = parity + 1;
  128.     Popup[I_STOP].choice = stop + 1;
  129.     Popup[I_HANDSHAKE].choice = Settings.handshake + 1;
  130.     SetCheck(dialog, C_DROP_DTR, Settings.dropDTR);
  131.     ShowWindow(dialog);
  132.  
  133.     for (;;) {
  134.         ModalDialog(Filter, &number);
  135.         switch(number) {
  136.             case B_OK:
  137.                 if (Popup[I_PORT].choice > 1)
  138.                     GetItem(Popup[I_PORT].h, Popup[I_PORT].choice,
  139.                         port);
  140.                 else
  141.                     port[0] = 0;
  142.                 if (err = PortSetUp(
  143.                         Popup[I_BAUD].choice - 1,
  144.                         Popup[I_DATA].choice - 1,
  145.                         Popup[I_PARITY].choice - 1,
  146.                         Popup[I_STOP].choice - 1,
  147.                         port,
  148.                         GetCheck(dialog,C_DROP_DTR),
  149.                         Popup[I_HANDSHAKE].choice - 1)) {
  150.                     Error(err, EmptyStr);
  151.                 }
  152.             case B_CANCEL:
  153.                 PopupCleanup();
  154.                 DisposDialog(dialog);
  155.                 return;
  156.             case C_DROP_DTR:
  157.                 ToggleCheckBox(dialog, number);
  158.                 break;
  159.         }
  160.     }
  161. }
  162.